package com.zxc.reggie.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zxc.reggie.common.BaseContext;
import com.zxc.reggie.common.R;
import com.zxc.reggie.entity.Orders;
import com.zxc.reggie.service.OrdersService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.time.LocalDateTime;

@RestController
@Slf4j
@RequestMapping("/order")
public class OrdersController {

    @Resource
    private OrdersService ordersService;

    @GetMapping("/userPage")
    public R<Page<Orders>> page(Integer page, Integer pageSize) {
        Page<Orders> ordersPage = new Page<>(page, pageSize);
        Long userId = BaseContext.getCurrentId();
        ordersPage = ordersService.query().eq("user_id",userId).orderByDesc("order_time").page(ordersPage);
        return R.success(ordersPage);
    }

    @PostMapping("/submit")
    public R<String> submit(@RequestBody Orders orders) {


        return ordersService.submit(orders);
    }
}
